package com.xujiakai.car.maintain.domain.entity;

import com.xujiakai.car.maintain.application.service.impl.BaseDataManageService;
import com.xujiakai.car.maintain.infrastructure.mapper.DaoFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class Mainitem {
    private Integer id;

    private String mainnumbering;

    private String projname;

    private Integer projcategoryid;

    private Double itemprice;

    private String mainflag;

    @Resource
    private DaoFactory daoFactory;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getMainnumbering() {
        return mainnumbering;
    }

    public void setMainnumbering(String mainnumbering) {
        this.mainnumbering = mainnumbering == null ? null : mainnumbering.trim();
    }

    public String getProjname() {
        return projname;
    }

    public void setProjname(String projname) {
        this.projname = projname == null ? null : projname.trim();
    }

    public Integer getProjcategoryid() {
        return projcategoryid;
    }

    public void setProjcategoryid(Integer projcategoryid) {
        this.projcategoryid = projcategoryid;
    }

    public Double getItemprice() {
        return itemprice;
    }

    public void setItemprice(Double itemprice) {
        this.itemprice = itemprice;
    }

    public String getMainflag() {
        return mainflag;
    }

    public void setMainflag(String mainflag) {
        this.mainflag = mainflag == null ? null : mainflag.trim();
    }

    public boolean modifyMainitem(com.xujiakai.car.maintain.domain.dto.MainitemDTO mainitem, String type) {
        boolean flag = false;
        if (mainitem != null) {
            try {
                if ("C".equals(type)) {// 添加信息
                    flag = daoFactory.getMainitemMapper().insertSelective(mainitem) > 0;
                } else if ("U".equals(type)) {
                    flag = daoFactory.getMainitemMapper().updateByPrimaryKeySelective(mainitem) > 0;
                } else if ("D".equals(type)) {
                    com.xujiakai.car.maintain.domain.dto.MainitemDTO mt = daoFactory.getMainitemMapper().selectByPrimaryKey(mainitem.getId());
                    if (mt != null) {
                        mt.setMainflag(mainitem.getMainflag());
                        flag = daoFactory.getMainitemMapper().updateByPrimaryKeySelective(mt) > 0;
                    }
                }
            } catch (Exception e) {
                BaseDataManageService.logger.error("修改维修项目类别的信息失败!");
            }
        }
        return flag;
    }
}